package org.hk.controller;

import org.hk.dao.AdminDao;
import org.hk.entity.Admin;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
//202020111许俊aaaa
//@WebServlet("/adminController")
public class AdminController //extends HttpServlet
{
    AdminDao adminDao;// dao 不 new但是能够使用是因为 spring的ioc（invers of controll 反转控制，对象的生成由容器（小容器spring 大容器tomcat）完成） 生成了对象

    public AdminDao getAdminDao() {
        return adminDao;
    }

    public void setAdminDao(AdminDao adminDao) {
        this.adminDao = adminDao;
    }

    public AdminController() throws IllegalAccessException, SQLException, ClassNotFoundException {
    }
//    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
//        response.setContentType("text/html;charset=utf-8");
//        PrintWriter out = response.getWriter();
//        try {
//            List<Admin> admins = adminDao.getAllAdmin();
//            StringBuilder adminsStr = new StringBuilder();
//            for(Admin admin:admins){
//                adminsStr.append(admin.toString());//我们覆盖了admin的toString方法
//            }
//            out.print(adminsStr.toString());
//            out.flush();
//            out.close();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        } catch (SQLException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        }
//
//    }
    public String getAll() throws IllegalAccessException, SQLException, InstantiationException {
        List<Admin> admins = adminDao.getAllAdmin();
//        StringBuilder adminsStr = new StringBuilder();
//        for (Admin admin : admins) {
//            adminsStr.append(admin.toString());//我们覆盖了admin的toString方法
//        }
        return "123322323";
    }
    public String update() throws IllegalAccessException, SQLException, InstantiationException {
        List<Admin> admins = adminDao.getAllAdmin();
//        StringBuilder adminsStr = new StringBuilder();
//        for (Admin admin : admins) {
//            adminsStr.append(admin.toString());//我们覆盖了admin的toString方法
//        }
        return "update";
    }
}
